package cn.tang.tframe.dubbox.filter;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * Created by tanghc on 2016/4/7.
 */
@Activate(group = Constants.PROVIDER,order = 110)
public class MonitorProviderFilter implements Filter {
	Logger logger = LoggerFactory.getLogger(this.getClass());
	public Result invoke(Invoker<?> invoker, Invocation inv)
			throws RpcException {
		logger.debug("========== monitor ====  dubbo provide  ==========");
		try {
			Map<String, String> attachments = inv.getAttachments();
			if(null != attachments ){
				String requestInfo = attachments.get("requestInfo");
				logger.debug("MonitorProviderFilter: requestInfo={}", requestInfo);
			}
		} catch (Exception e) {
			logger.error("dubbo MonitorProviderFilter exception: "+e.getMessage());
		}
		Result invoke = invoker.invoke(inv);
		return invoke;
	}
}
